class Solution {
    public int minDays(int[] bloomDay, int m, int k) {
        int left = 0;
        int right = Arrays.stream(bloomDay).max().getAsInt();
        int len = bloomDay.length;
        if (m > bloomDay.length / k) {
            return -1;
        }
        while (left < right)
        {
            int mid = (left + right) >> 1;
            if (check(bloomDay, mid, k) >= m)
            {
                right = mid;
            }
            else
                left = mid + 1;
        }
        return right;
    }
    public int check(int[] bloomDay, int mid, int k)
    {
        int count = 0;
        int res = 0;
        for (int x : bloomDay)
        {
            if (x <= mid)
            {
                count++;
                if (count == k)
                {
                    res++;
                    count = 0;
                }
            }
            else count = 0;
        }
        return res;
    }
}